const storage = {};

const tMailSetting = storages.create("tMailSetting");
const jdSetting = storages.create("jdSetting");

// 设置淘宝脚本缓存
storage.setTMailSettings = function setTMailSettings(buyTime, taobaoEarlyTime) {
  tMailSetting.put("buyTime", buyTime);
  tMailSetting.put("taobaoEarlyTime", taobaoEarlyTime);
}

// 获取淘宝脚本缓存
storage.getTMailSettings = function getTMailSettings() {
  return {
    buyTime: tMailSetting.get("buyTime") ? tMailSetting.get("buyTime") : 5,
    taobaoEarlyTime: tMailSetting.get("taobaoEarlyTime") ? tMailSetting.get("taobaoEarlyTime") : 200
  }
}

// 设置京东脚本缓存
storage.setJDSettings = function setJDSettings(mode, buyTime) {
  jdSetting.put("mode", mode);
  jdSetting.put("buyTime", buyTime);
}

// 获取京东脚本缓存
storage.getJDSettings = function getJDSettings() {
  return {
    mode: jdSetting.get("mode") ? jdSetting.get("mode") : "detailMode",
    buyTime: jdSetting.get("buyTime") ? jdSetting.get("buyTime") : 30,
  }
}

// 清空缓存
storage.clear = function () {
  // 清空设置
  tMailSetting.clear();
  jdSetting.clear();
}

module.exports = storage;